﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    public static UIManager instance;

    public GameObject healthbar;
    public GameObject gameoverpanle;

    public Slider BossHealthbar;
    

    [Header ("UI Elements")]
    public GameObject PauseMenu;
    public void Awake()
    {
        if (instance == null)
            instance = this;
        else
            Destroy(gameObject);

    }
    public void UpdateHealthbar(float currentHealth)//current 指的是当前的，current Health就是当前生命值的一个盒子

    {
        switch(currentHealth)
        {
            case 3:
                healthbar.transform.GetChild(0).gameObject.SetActive(true);
                healthbar.transform.GetChild(1).gameObject.SetActive(true);
                healthbar.transform.GetChild(2).gameObject.SetActive(true);
                break;
            case 2:
                healthbar.transform.GetChild(0).gameObject.SetActive(true);
                healthbar.transform.GetChild(1).gameObject.SetActive(true);
                healthbar.transform.GetChild(2).gameObject.SetActive(false);
                break;
            case 1:
                healthbar.transform.GetChild(0).gameObject.SetActive(true);
                healthbar.transform.GetChild(1).gameObject.SetActive(false);
                healthbar.transform.GetChild(2).gameObject.SetActive(false);
                break;
            case 0:
                healthbar.transform.GetChild(0).gameObject.SetActive(false);
                healthbar.transform.GetChild(1).gameObject.SetActive(false);
                healthbar.transform.GetChild(2).gameObject.SetActive(false);
                break;
        }
            
        

    }
    public void PauseGame()
    {
        PauseMenu.SetActive(true);

        Time.timeScale = 0;
    }
    public  void ResumeGame()
    {
        PauseMenu.SetActive(false);

        Time.timeScale = 1;
    }
    public void SetBossHealth(float health)
    {
        BossHealthbar.maxValue = health;
    }
    public void UpadateBossHealthbar(float health)
    {
        BossHealthbar.value = health;
    }
    public void GameoverUI(bool playerDead)
    {
        gameoverpanle .SetActive(playerDead);
    }
}
